using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using System.Threading.Tasks;

namespace GetStartedApp.ViewModel.Page
{
    public partial class CommandPageViewModel : ViewModelBase
    {
        public CommandPageViewModel()
        {
            RobotName = "aa";
        }

        /// <summary>
        /// 机器人名字
        /// </summary>
        [ObservableProperty]
        private string? _robotName;

        [RelayCommand]
        private void OpenThePodBayDoors()
        {
            ConversationLog.Clear();
            AddToConvo("对不起，戴夫，我恐怕不能这么做.");
        }

        [RelayCommand]
        public void OpenThePodBayDoorsFellowRobot(string? robotName)
        {
            ConversationLog.Clear();
            AddToConvo($"Hello {robotName}, the Pod Bay is open :-)");
        }

        [RelayCommand]
        public async Task OpenThePodBayDoors2Async()
        {
            ConversationLog.Clear();
            AddToConvo("Preparing to open the Pod Bay...");

            // wait a second
            await Task.Delay(1000);

            AddToConvo("Depressurizing Airlock...");

            // wait 2 seconds
            await Task.Delay(2000);

            AddToConvo("Retracting blast doors...");

            // wait 2 more seconds
            await Task.Delay(2000);

            AddToConvo("Pod Bay is open to space!");
        }

        /// <summary>
        ///  This collection will store what the computer said
        /// </summary>
        public ObservableCollection<string> ConversationLog { get; } = new ObservableCollection<string>();

        // Just a helper to add content to ConversationLog
        private void AddToConvo(string content)
        {
            ConversationLog.Add(content);
        }
    }
}